﻿// -------------------------------------------------------------------------
//    @FileName         :    NFExprCheck.h
//    @Author           :    Gao.Yi
//    @Date             :    2025-09-30
//    @Email			:    445267987@qq.com
//    @Module           :    NFExprCheck
//    @Desc             :
//
// -------------------------------------------------------------------------

#pragma once

#include "NFLogMgr.h"
#include "NFCheck.h"

#include <float.h>
#include <limits.h>
#include <vector>
#include <stack>

#define EXPR_LOG 1

enum enExprOp
{
    EN_EXPR_OP_NONE = 0,
    EN_EXPR_OP_PLUS = 1,
    EN_EXPR_OP_SUB  = 2,
    EN_EXPR_OP_MUL  = 3,
    EN_EXPR_OP_DIV  = 4,
};

class CExprSymbol
{
public:
    CExprSymbol();
    CExprSymbol(double llfNum);
    CExprSymbol(enExprOp eOp);
    ~CExprSymbol();

public:
    static std::string GetOpStr(enExprOp eOp);

public:
    bool IsNum();
    bool IsOp();
    double GetNum() const;
    enExprOp GetOp() const;

public:
    std::string DebugString();

private:
    double m_llfNum;
    enExprOp m_eOp;
};

class CExprCheck
{
public:
    CExprCheck();
    virtual ~CExprCheck();

public:
    double GetRet() const;

    bool NeedCalc() const;
    int SetNeedCalc();
    int ClearNeedCalc();

    bool IsOverflow() const;
    int SetOverflow();
    int ClearOverflow();

public:
    int PushNum(double llfNum);
    int PushOp(enExprOp eOp);
    int PushOp(char c);

public:
    int CalcExprInt64();
    int CalcExpr(double llfMinBound = -DBL_MAX, double llfMaxBound = DBL_MAX);
    double CalcExpr(double llfNum1, double llfNum2, enExprOp eOp);

public:
    std::string DebugString();

private:
    std::vector<CExprSymbol> m_vecSymbol;
    bool m_bNeedCalc;
    bool m_bOverflow;
    double m_llfRet;
};